<!doctype html>
<html>
<head>
  <title>文档管理</title>
  <meta  name = "viewport" content = "initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no">
  <script src="webix/webix.js?v=6.4.6" type="text/javascript"></script>
  <script src="filemanager.js?v=6.4.6" type="text/javascript"></script>
  <link rel="stylesheet" type="text/css" href="webix/webix.css?v=6.4.6">
  <link rel="stylesheet" type="text/css" href="filemanager.css?v=6.4.6">
  <link rel="stylesheet" href="layui/layui.css">
  <script src="layui/layui.js" type="text/javascript"></script>
  <style type="text/css">
    .fit_parent {
      max-width: 100%;
      max-height: 100%;
    }
  </style>
</head>
<body>
<script type="text/javascript">
  // 获取token
  var token = window.location.search.split('=')[1]
  var layer;
  layui.use('layer', function(){
    layer = layui.layer;
  });
  webix.ready(function(){
    var selectId = "";
    webix.ui({
      view:"filemanager",
      id:"files",
      url: "/api/erp/oa/fileManager/checkList?token=" + token,
      handlers:{
        "download": "/api/erp/oa/fileManager/download?token=" + token,
        "preview": "/api/erp/oa/fileManager/preview?token=" + token,
      },
      ready:function(){
        this.getMenu().add({
          id: "preview",
          icon: "webix_icon wxi-search",
          value: "预览",
          batch: "file",
          method:"previewFile"
        }, 0);
        this.getMenu().add({
          id: "download",
          icon: "webix_icon wxi-download",
          value: "下载",
          batch: "file",
          method:"download"
        }, 1);
        this.getMenu().remove("create");
        this.getMenu().remove("edit");
        this.getMenu().remove("auth");
        this.getMenu().remove("remove");
        this.getMenu().remove("upload");
      }
    });

    //双击文件下载提示
    $$("files").attachEvent("onBeforeRun",function(id){
      webix.confirm({
        text:"是否下载该文件?",
        ok:"是",
        cancel:"否",
        callback:function(result){
          if(result) $$("files").download(id);
        }
      });
      return false;
    });

    var actions = $$("files").getMenu();
    actions.attachEvent("onItemClick", function(id, e, node){
      selectId = $$("files").getActive();
      if(id == "auth"){
        webix.ui({
          view:"popup",
          height:500,
          width:1000,
          left:500,
          top:200,
          head:"文件授权",
          body:webix.copy(form)
        }).show();
      }else if(id == "preview"){
        if (selectId instanceof Array) {
          layer.msg('暂不支持批量预览！')
          return;
        }
        webix.ajax().get(`/api/erp/oa/fileManager/preview?id=${selectId}&token=${token}`, function (data) {
          data = JSON.parse(data);
          if (data.contentType.indexOf('image') !== -1) {
            layer.open({
              type: 1,
              title:"图片预览",
              shift: 2,
              content: `<img src="/api/erp/oa/fileManager/previewFile?id=${selectId}&token=${token}"/>`,
              area: ['750px', '600px'],
              btn: ['取消']
            });
          } else {
            window.open(`/api/erp/oa/fileManager/previewFile?id=${selectId}&token=${token}`)
          }
        })
      }
    });
  });
</script>
</body>
</html>